﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Xunit;

namespace Windy.Json
{
    public class JsonStreamTest
    {
        private static readonly string JsonText = "[123,12.3,-1.23456789012345e-25,{'true':true,\"false\":false,{'null':null}},['\\n\\r\\'\\\"',\"\\u6587\\u8fea\"]]";

        private static readonly JsonNotation[] JsonNotations = new[]
            {
                JsonNotation.ArrayBegin,
                new JsonNotation(123m),
                JsonNotation.MemberSeperator,
                new JsonNotation(12.3m),
                JsonNotation.MemberSeperator,
                new JsonNotation(-1.23456789012345e-25),
                JsonNotation.MemberSeperator,
                JsonNotation.ObjectBegin,
                new JsonNotation("true"),
                JsonNotation.NameSeperator,
                JsonNotation.True,
                JsonNotation.MemberSeperator,
                new JsonNotation("false"),
                JsonNotation.NameSeperator,
                JsonNotation.False,
                JsonNotation.MemberSeperator,
                JsonNotation.ObjectBegin,
                new JsonNotation("null"),
                JsonNotation.NameSeperator,
                JsonNotation.Null,
                JsonNotation.ObjectEnd,
                JsonNotation.ObjectEnd,
                JsonNotation.MemberSeperator,
                JsonNotation.ArrayBegin,
                new JsonNotation("\n\r'\""),
                JsonNotation.MemberSeperator,
                new JsonNotation("文迪"),
                JsonNotation.ArrayEnd,
                JsonNotation.ArrayEnd
            };


        [Fact(Skip = "Large Number and Unicode Escape doesn't work well")]
        public void ToStringTest()
        {
            Assert.Equal(JsonText, JsonNotations.ToJsonText());
        }

        [Fact()]
        public void TextParseTest()
        {
            Assert.Equal(JsonNotations, JsonText.ParseAsJson().ToArray());
        }

        [Fact()]
        public void ParseJsonStringTest()
        {
            Assert.Equal(new JsonNotation("abc"), "'abc'".ParseAsJson().First());
        }

        [Fact()]
        public void ParseJsonNumberTest()
        {
            Assert.Equal(new JsonNotation(-123.456m), "-123.456".ParseAsJson().First());
        }

        [Fact()]
        public void ParseJsonLitterlTest()
        {
            Assert.Equal(JsonNotation.True, "true".ParseAsJson().First());
            Assert.Equal(JsonNotation.False, "false".ParseAsJson().First());
            Assert.Equal(JsonNotation.Null, "null".ParseAsJson().First());
        }

        [Fact()]
        public void SperatorExtreamTest()
        {
            var notations = "{\"::::::\":'::::::,,,,,::::,,,',',,,,,':',,,,,,,,:::::'}".ParseAsJson().ToArray();
            var expected = new JsonNotation[]
            {
                JsonNotation.ObjectBegin,
                new JsonNotation("::::::"),
                JsonNotation.NameSeperator,
                new JsonNotation("::::::,,,,,::::,,,"),
                JsonNotation.MemberSeperator,
                new JsonNotation(",,,,,"),
                JsonNotation.NameSeperator,
                new JsonNotation(",,,,,,,,:::::"),
                JsonNotation.ObjectEnd,
            };
            Assert.Equal(expected, notations);
        }


        [Fact( )]
        public void WhitetySpaceTest()
        {
            var json = "\r\n\t[\t\r\n\t\t\t   true\r\n\t  ,\t\r\n 'abc'  \t\r\n,\t\r \n123.3e2 \r\t\n]\r\n\t ";
            var expected = new JsonNotation[]
            {
                JsonNotation.ArrayBegin,
                JsonNotation.True,
                JsonNotation.MemberSeperator,
                new JsonNotation("abc"),
                JsonNotation.MemberSeperator,
                new JsonNotation(123.3e2m),
                JsonNotation.ArrayEnd
            };

            Assert.Equal(expected, json.ParseAsJson().ToArray());
        }
	
  
    }
}
